package com.tepth.vehiclemaintenance.mvp.work.detail;

import android.app.Activity;
import android.app.Dialog;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.tepth.vehiclemaintenance.R;
import com.tepth.vehiclemaintenance.bean.MaintainListWork;
import com.tepth.vehiclemaintenance.event.StartBrotherEvent;
import com.tepth.vehiclemaintenance.mvp.work.search.SearchFragment;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;


/**
 * Created by zhangyu on 2017/3/21.
 */

public class ChooseOperatorDialog extends Dialog {

    public ChooseOperatorDialog(@NonNull final Activity context, final ArrayList<MaintainListWork.ListContentsBean.ListRemarkBean.OperationBean> list) {
        super(context);
        View view = LayoutInflater.from(context).
                inflate(R.layout.dialog_choose_actions, null);
        ListView listView = (ListView) view.findViewById(R.id.list_view);
        if (list == null) {
            return;
        }
        ArrayAdapter<MaintainListWork.ListContentsBean.ListRemarkBean.OperationBean> adapter = new ArrayAdapter<>(context, R.layout.item_text, list);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                EventBus.getDefault().post(new StartBrotherEvent(SearchFragment.newInstance
                        (list.get(position))));
                dismiss();
            }
        });
        setContentView(view);
    }

}
